package OldCode;
/*
 * Created on Oct 17, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
//import java.awt.event.*;
import java.util.*;


/**
 * @author sszhao
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class SunburstMenuBasic extends JPanel {
	
	//I will keep these constants for now, although some of them might not
	//be useful, but I might need to use them later
	
	//===========================================================================
	  //===   CONSTANTS   =========================================================

	  /** Where the first pie slice is rendered. Currently North.  */
	  public static final double DEFAULT_START = Math.PI / 2;

	  /** Default radius size for the pie menu, currently 100.  */
	  public static final int DEFAULT_BIG_RADIUS = 100;

	  /** The radius of the small inner circle, currently 20.  */
	  public static final int DEFAULT_SMALL_RADIUS = 20;

	  /**
	   * The default delay (msec) before pie menus initially pop up, currently
	   * 200ms. Don't make this too small, or you'll get strange errors.
	   */
	  public static final long DEFAULT_INITIAL_DELAY = 200;

	  /** The default delay (msec) before pie submenus pop up, currently 500ms.  */
	  public static final long DEFAULT_SUBMENU_DELAY = 500;

	  /** Default value for auto-open is false.  */
	  public static final boolean DEFAULT_AUTO_OPEN = false;

	  /** Default value for clipping is false.  */
	  public static final boolean DEFAULT_CLIP_FLAG = false;

	  /**
	   * The default scaling factor for where to draw objects.
	   * This scaling factor is multiplied with the radius to determine
	   * where to draw things. Currently 0.65.
	   */
	  public static final double DEFAULT_SCALING_FACTOR = 0.65;

	  //-----------------------------------------------------------------

	  /** The default color of the pie menu, currently light gray.  */
	  public static final Color DEFAULT_FILL_COLOR = new Color(204, 204, 204);;

	  /** The default color of the lines in the pie menu, currently black.  */
	  public static final Color DEFAULT_LINE_COLOR = new java.awt.Color(0,0,0,0.35f);

	  /**
	   * The default color of the selected item in the pie menu, currently gray.
	   */
	  public static final Color DEFAULT_SELECTED_COLOR = new Color(167, 167, 167);

	  /** The default color of fonts, currently black.  */
	  public static final Color DEFAULT_FONT_COLOR = Color.black;

	  /** The default font, currently sans serif plain, 15 point.  */
	  public static final Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 15);

	  /** Default line width for drawing lines in the Pie Menu, currently 0.7.  */
	  public static final float DEFAULT_LINE_WIDTH = 0.7f;

	  //-----------------------------------------------------------------

	  private static final int STATE_TAP_OPEN     = 90;
	  private static final int STATE_TAPHOLD_OPEN = 91;
	  private static final int STATE_DRAG_OPEN    = 92;
   
	  private static final int ORIENT_TOP    = 1;
	  private static final int ORIENT_TOPRIGHT  = 2;
	  private static final int ORIENT_BOTTOM = 3;
	  private static final int ORIENT_TOPLEFT   = 4;
	  private static final int ORIENT_BOTRIGHT = 5;
	  private static final int ORIENT_BOTLEFT = 6;

	  //===   CONSTANTS   =========================================================
	  //===========================================================================



	  //===========================================================================
	  //===   CLASS METHODS FOR PIE MENU DEFAULTS   ===============================

	  //// State tracking - turns submenus and select on or off globally.
	  static boolean enableSubmenus              = true;
	  static boolean enableSelect                = true;

	  //// Global behavior of all pie menus
	  static boolean defaultAutoOpen             = DEFAULT_AUTO_OPEN;
	  static int     defaultOpenState            = STATE_TAP_OPEN;
	  static boolean defaultRelocateSubmenusFlag = true;
	  static long    defaultInitialDelay         = DEFAULT_INITIAL_DELAY;
	  static long    defaultSubmenuDelay         = DEFAULT_SUBMENU_DELAY;
	  static boolean defaultFlagPenMode          = false;

	  //// Appearance defaults
	  static Color   defaultFillColor            = DEFAULT_FILL_COLOR;
	  static Color   defaultLineColor            = DEFAULT_LINE_COLOR;
	  static Color   defaultSelectedColor        = DEFAULT_SELECTED_COLOR;
	  static Color   defaultFontColor            = DEFAULT_FONT_COLOR;
	  static Font    defaultFont                 = DEFAULT_FONT;
	  static float   defaultLineWidth            = DEFAULT_LINE_WIDTH;
	  static int     defaultBigRadius            = DEFAULT_BIG_RADIUS;
	  static int     defaultSmallRadius          = DEFAULT_SMALL_RADIUS;
	  static double  defaultScalingFactor        = DEFAULT_SCALING_FACTOR;
	  static boolean defaultClipFlag             = DEFAULT_CLIP_FLAG;
	  static boolean defaultFlagLineNorth        = false;
	  static Image   defaultSubmenuIcon          = null;

	//===========================================================================
	  //===   NONLOCAL VARIABLES   ================================================

	  //// PieMenu appearance variables
	  Color             fillColor;                   // color of filled background
	  Color             lineColor;                   // color of lines
	  Color             fontColor;                   // color of font
	  Color             selectedColor;               // the color of selected item
	  Color             defaultSelectedItemColor;    // translucent selectedColor
	  Font              font;                        // the font to use
	  boolean           flagLineNorth;               // draw line to north?
	  //BlinkTimer        timer;                       // timer for blinking

	  transient Image       submenuIconImage;        // arrow image for submenus
	  transient BasicStroke stroke;                  // stroke characteristics

	  //// Event handling variables
	  //PieMenuListener   lstnr;                       // mouse listener on ourself
	  //ItemListener      clistener;                   // listens to the parent
	  //MouseEvent        lastEvent;                   // last mouse event occurring
	  //PieMenuHandler    handler;                     // actually handles events
	  boolean           flagCanAbortSubmenu;         // hack to make it work -
													 //   once you click, you
													 //   cannot abort. But you
													 //   can abort if you didn't
													 //   click (ie drag or move)
	  boolean           flagDraggedInPieMenu;        // did we drag in the pie
													 //   menu? If so, don't
													 //   let the left-mouse
													 //   button close the pie
													 //   menu. Let it activate
													 //   an item instead.
	  boolean           flagJustClosedSubmenu;       // did we just close a
													 //   submenu? If so, don't
													 //   forward move or drag
													 //   events to the pie slice
													 //   that contained the
													 //   submenu. Otherwise, the
													 //   pie slice could get
													 //   reactivated too quickly.
	  boolean           flagJustOpened;              // there are problems with
													 //   tap-hold, since if you
													 //   release the button
													 //   immediately after
													 //   opening, the pie menu
													 //   closes, which is not the
													 //   behavior you want.
	  private boolean flagAcceptLeft  = false;
	  private boolean flagAcceptMid   = false;
	  private boolean flagAcceptRight = false;

	  //// Graphics and shape variables
	  int                 radius;                    // radius of the pie menu
	  int                 smallRadius;               // radius of inner circle
	  transient Ellipse2D bigCircle;                 // the actual pie menu
	  transient Ellipse2D smallCircle;               // small circle within
	  transient Ellipse2D clipCircle;                // clipping boundaries
	  transient Map       newHints;                  // rendering hints

	  //// Pie Menu behavior variables
	  boolean           flagPenMode;
	  double            scalingFactor;               // how much to scale radius
													 //    when rendering text

	  //// Pie Menu variables
	  String            strText;                     // text name of this menu
	  Icon              icon;                        // an icon for this menu
	  Container         parent;                      // the component we are on
	  java.util.List    list;                        // list of menu items
	  int               selected        = -1;        // # of item selected
	  int               defaultSelected = -1;        // item to select by default
	  //ShowThread        showThread;                  // thread to show the menu
	  //ShowSubmenuThread submenuThread;               // thread to show submenu
	  int               submenuPos;                  // menu position of submenu
	  //PieMenu           submenu;                     // the submenu
													 //    null if none open
	  //PieMenu           parentMenu = null;           // the parent menu
													 //   of this submenu
													 //   (if it is one)

	  //// Listeners
	  ArrayList         popupMenuListeners;          // listeners on the popup


	/**
	   * Create a pie menu on the specified applet.
	   */
	  public SunburstMenuBasic() {
		 this(DEFAULT_BIG_RADIUS);
	  } // of constructor

	  //-----------------------------------------------------------------

	  public SunburstMenuBasic(int radius) {
		 this("", null, radius);
	  } // of constructor

	  //-----------------------------------------------------------------

	  public SunburstMenuBasic(String str) {
		 this(str, null, DEFAULT_BIG_RADIUS);
	  } // of constructor

	  //-----------------------------------------------------------------

	  public SunburstMenuBasic(String str, Icon icon) {
		 this(str, icon, DEFAULT_BIG_RADIUS);
	  } // of constructor

	  //-----------------------------------------------------------------

	  public SunburstMenuBasic(String str, int radius) {
		 this(str, null, radius);
	  } // of constructor

	  //-----------------------------------------------------------------

	  /**
	   * Create a pie menu with the specified parameters.
	   *
	   * @param str    is the name of this pie menu.
	   * @param icon   is the icon for this pie menu.
	   * @param radius is the intiial radius of the pie menu.
	   */
	  public SunburstMenuBasic(String str, Icon icon, int radius) {
		 //// 0.1. Initialize to defaults.
		 setFillColor(getDefaultFillColor());
		 setLineColor(getDefaultLineColor());
		 setFontColor(getDefaultFontColor());
		 setSelectedColor(getDefaultSelectedColor());
		 setFont(getDefaultFont());
		 setLineWidth(getDefaultLineWidth());
		 setLineNorth(getDefaultLineNorth());
		 setScalingFactor(getDefaultScalingFactor());

		 //submenuIconImage     = getDefaultSubmenuIcon();

		 //// 0.2. Initialize some behaviors.
		 bigCircle            = new Ellipse2D.Double();
		 smallCircle          = new Ellipse2D.Double();
		 clipCircle           = new Ellipse2D.Double();
		 list                 = new ArrayList();
		 //timer                = new BlinkTimer();
		 setDoubleBuffered(true);

		 //// 0.3. Initialize the listeners.
		 popupMenuListeners = new ArrayList();

		 //// 0.4. Only draw what we say to draw, don't draw anything else.
		 ////      If this is true, then we get some strange repaint problems.
		 setOpaque(false);

		 //// 1. Setup the listener that we will attach to the parent,
		 ////    and the one we will attach to ourself.
		 //handler   = new PieMenuHandler();
		 //lstnr     = new PieMenuListener();
		 //clistener = new ItemListener();

		 //// 2. Setup Component stuff, our location, visibility, and font.
		 setLocation(0, 0);
		 setVisible(true);
		 setFont(getDefaultFont());

		 //// 3. Set the radius, string, and icon.
		 setBigRadius(getDefaultBigRadius());
		 setSmallRadius(getDefaultSmallRadius());
		 //setIcon(icon);
		 //setText(str);

		 //// 4. And now setup a listener on ourself.
		 //addMouseListener(lstnr);
		 //addMouseMotionListener(lstnr);

		 //// 5. Setup the rendering hints.
		 newHints = new HashMap();
		 newHints.put(RenderingHints.KEY_ANTIALIASING,
					  RenderingHints.VALUE_ANTIALIAS_ON);
		 newHints.put(RenderingHints.KEY_COLOR_RENDERING,
					  RenderingHints.VALUE_COLOR_RENDER_QUALITY);
		 newHints.put(RenderingHints.KEY_RENDERING,
					  RenderingHints.VALUE_RENDER_QUALITY);
		 newHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
					  RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	  } // of default constructor
	  
	  
	/**
		* Set the color of the pie menu items.
		*/
	   public void setFillColor(Color newColor) {
		  fillColor = newColor;
	   } // of method

	  

	   //-----------------------------------------------------------------

	   /**
		* Set the color lines are rendered in.
		*/
	   public void setLineColor(Color newColor) {
		  lineColor = newColor;
	   } // of method

	 
	   //-----------------------------------------------------------------

	   /**
		* Set the color of the selected item.
		*/
	   public void setSelectedColor(Color newColor) {
		  selectedColor = newColor;
		  defaultSelectedItemColor = new Color(selectedColor.getRed(),
			 selectedColor.getGreen(), selectedColor.getBlue(), 127);
	   } // of method

	   

	   //-----------------------------------------------------------------

	   /**
		* Set the color text is rendered in.
		*/
	   public void setFontColor(Color newColor) {
		  fontColor = newColor;
	   } // of method

	   /**
		* Get the color text is rendered in.
		*/
	   public Color getFontColor() {
		  return (fontColor);
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set the font the pie menu will use.
		*/
	   public void setFont(Font newFont) {
		  super.setFont(newFont);
	   } // of method

	   /**
		* Get the font the pie menu will use.
		*/
	   public Font getFont() {
		  return (super.getFont());
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set the line width for the pie menu.
		*/
	   public void setLineWidth(float newWidth) {
		  stroke = new BasicStroke(newWidth);
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set the radius for the pie menu.
		*
		* @param radius is the radius of the pie menu from the center.
		*/
	   public void setBigRadius(int radius) {
		  if (radius > 0) {
			 //// 1. Setup the radius. Actually set our size to be slightly
			 ////    larger than the radius.
			 this.radius = radius;
			 setSize(2*radius + 1, 2*radius + 1);

			 //// 2. Update the min, max, and preferred sizes.
			 Dimension dim = new Dimension(2*radius, 2*radius);
			 setMinimumSize(dim);
			 setMaximumSize(dim);
			 setPreferredSize(dim);

			 //// 3. Now update the bigCircle shape.
			 updateShape();
		  }
	   } // of method

	   /**
		* Get the radius for the pie menu.
		*/
	   public int getBigRadius() {
		  return (radius);
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set the radius of the inner circle for the pie menu.
		*/
	   public void setSmallRadius(int newRadius) {
		  this.smallRadius = newRadius;
		  updateShape();
	   } // of method

	   /**
		* Get the radius of the inner circle for the pie menu.
		*/
	   public int getSmallRadius() {
		  return (smallRadius);
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set the scaling factor for the pie menu.
		*/
	   public void setScalingFactor(double newScalingFactor) {
		  scalingFactor = newScalingFactor;
	   } // of method

	   /**
		* Get the scaling factor for the pie menu.
		*/
	   public double getScalingFactor() {
		  return (scalingFactor);
	   } // of method

	   //-----------------------------------------------------------------

	   /**
		* Set whether we draw a line to north, or draw the first slice such
		* that it is centered on north.
		*
		* @param flag is true if a line is to be drawn to north, false otherwise.
		*/
	   public void setLineNorth(boolean flag) {
		  flagLineNorth = flag;
	   } // of method

	 

	/**
	  * Set the default fill color for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultFillColor(Color newColor) {
		defaultFillColor = newColor;
	 } // of method

	 /**
	  * Get the default fill color for all new pie menus created.
	  */
	 public static Color getDefaultFillColor() {
		return (defaultFillColor);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default line color for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultLineColor(Color newColor) {
		defaultLineColor = newColor;
	 } // of method

	 /**
	  * Get the default line color for all new pie menus created.
	  */
	 public static Color getDefaultLineColor() {
		return (defaultLineColor);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default selected color for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultSelectedColor(Color newColor) {
		defaultSelectedColor = newColor;
	 } // of method

	 /**
	  * Get the default selected color for all new pie menus created.
	  */
	 public static Color getDefaultSelectedColor() {
		return (defaultSelectedColor);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default font color for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultFontColor(Color newColor) {
		defaultFontColor = newColor;
	 } // of method

	 /**
	  * Get the default font color for all new pie menus created.
	  */
	 public static Color getDefaultFontColor() {
		return (defaultFontColor);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default font for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultFont(Font newFont) {
		defaultFont = newFont;
	 } // of method

	 /**
	  * Get the default font for all new pie menus created.
	  */
	 public static Font getDefaultFont() {
		return (defaultFont);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default line width for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultLineWidth(float newLineWidth) {
		defaultLineWidth = newLineWidth;
	 } // of method

	 /**
	  * Get the default line width for all new pie menus created.
	  */
	 public static float getDefaultLineWidth() {
		return (defaultLineWidth);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default radius for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultBigRadius(int newRadius) {
		defaultBigRadius = newRadius;
	 } // of method

	

	 //-----------------------------------------------------------------

	 /**
	  * Set the default radius of the inner circle for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultSmallRadius(int newRadius) {
		defaultSmallRadius = newRadius;
	 } // of method

	 

	 //-----------------------------------------------------------------

	 /**
	  * Set the default scaling factor for all new pie menus created
	  * after this value is set.
	  */
	 public static void setDefaultScalingFactor(double newScalingFactor) {
		defaultScalingFactor = newScalingFactor;
	 } // of method

	 /**
	  * Get the default scaling factor for all new pie menus created.
	  */
	 public static double getDefaultScalingFactor() {
		return (defaultScalingFactor);
	 } // of method

	 //-----------------------------------------------------------------

	 /**
	  * Set the default for whether or not the first line drawn should be north
	  * or if the first pie slice should be drawn north. Only takes effect
	  * for new pie menus created after this value is set.
	  */
	 public static void setDefaultLineNorth(boolean flag) {
		defaultFlagLineNorth = flag;
	 } // of method

	 /**
	  * Get the default for whether or not the first line drawn should be north
	  * or if the first pie slice should be drawn north.
	  */
	 public static boolean getDefaultLineNorth() {
		return (defaultFlagLineNorth);
	 } // of method
	  
	  
	/**
		* Get the default for whether or not pie menus should be clipped to
		* circular bounds for all new pie menus created.
		*/
	   public static boolean getAllClipping() {
		  return (defaultClipFlag);
	   } // of method
	   
	/**
		* Get whether we draw a line to north, or draw the first slice such
		* that it is centered on north.
		*/
	   public boolean getLineNorth() {
		  return (flagLineNorth);
	   } // of method
	   
	/**
	   * Get the color of the pie menu items.
	   */
	  public Color getFillColor() {
		 return (fillColor);
	  } // of method
	  
	/**
		* Get the color of the selected item.
		*/
	   public Color getSelectedColor() {
		  return (selectedColor);
	   } // of method
	   
	   
	/**
	   * Get the color lines are rendered in.
	   */
	  public Color getLineColor() {
		 return (lineColor);
	  } // of method

	/**
		* Get the default radius for all new pie menus created.
		*/
	   public static int getDefaultBigRadius() {
		  return (defaultBigRadius);
	   } // of method
	   
	/**
	   * Get the default radius of the inner circle for all new pie menus created.
	   */
	  public static int getDefaultSmallRadius() {
		 return (defaultSmallRadius);
	  } // of method
	   
	/**
	   * Update the shape of this PieMenu whenever the location or radius is
	   * changed.
	   */
	  protected void updateShape() {
		 //// 1. Since our top-left corner is (0, 0), the shape is simply a
		 ////    circle from (0, 0) to the width and height, both of which
		 ////    should be 2*radius.
		 Rectangle bounds = getBounds();
		 bigCircle.setFrame(0, 0, 2*radius, 2*radius);
		 clipCircle.setFrame(-2, -2, 2*radius + 4, 2*radius + 4);
		 smallCircle.setFrame(radius - smallRadius, radius - smallRadius,
							  2*smallRadius, 2*smallRadius);
	  } // of method
	  
	public int getItemCount() {
		return (list.size());
	 } // of method
	 
	 
	 public JComponent addItem(JComponent item){
	 	list.add(item);
	 	return item;
	 }
	  
	   /**
		* Get the radian of the first position. We always start at north.
		*/
	   private double getStartRadian() {
		  int    numItems = getItemCount();

		  if (getLineNorth() == true || numItems <= 1) {
			 return (DEFAULT_START);
		  }
		  else {
			 double offset = 2*Math.PI / numItems;
			 return (DEFAULT_START - offset / 2);
		  }
	   } // of method
	   

	   
	public void paintComponent(Graphics g) {
		 //// 0.1. Cast as Graphics2D.
		 Graphics2D gg   = (Graphics2D) g;
		 Color      oldc = g.getColor();

		 //// 0.2. Should we do clipping?
		 if (getAllClipping() == true) {
			gg.setClip(clipCircle);
		 }

		 //// 0.3. Set the rendering quality to make it higher.
		 Map oldHints = (Map) gg.getRenderingHints();
		 gg.setRenderingHints(newHints);

		 //// 0.4. Set the rendering attributes.
		 ////      Font is set automatically for us. Stroke is not. Why?
		 ////      Who knows? It's certainly a strange design decision.
		 gg.setStroke(stroke);
		 gg.setPaintMode();

		 //// 0.5. Get the selected item number so we can highlight it later.
		 int selectedItem        = 1; //getSelectedItem();
		 int defaultSelectedItem = 1; //getDefaultSelectedItem();

		 //// 1. Draw the boundary lines. Do nothing if no elements.
		 ////    First, calculate the radians required by each element.
		 int numItems = getItemCount();
		 if (numItems <= 0) {
			gg.setColor(getFillColor());
			gg.fillOval(0, 0, 2*radius, 2*radius);
		 }
		 else {
			double     stepRadian    = 2*Math.PI / numItems;
			double     currentRadian = getStartRadian();
			Shape      oldClip       = null;
			JComponent item;
			String     text;
			Icon       icon;
			Arc2D      arc;
			//// 1.1. For each element, draw a line from (radius, radius) to
			////      the endpoint.
			gg.setColor(getLineColor());
			for (int i = 0; i < numItems; i++) {
			   //// 1.1.1. Calculate the arc size.
			   arc = new Arc2D.Float(0, 0, 2*radius, 2*radius,
						(float) Math.toDegrees(currentRadian),
						(float) Math.toDegrees(stepRadian), Arc2D.PIE);

			   //// 1.1.2. Color in the selected item.
			   if (selectedItem == i) {
				  gg.setColor(getSelectedColor());
				  gg.fill(arc);
			   }
			   //// 1.1.3. Otherwise, color in the normal fill color.
			   else {
				  gg.setColor(getFillColor());
				  gg.fill(arc);

				  //// 1.1.4. Color in the default selected item.
				  if (defaultSelectedItem == i) {
					 gg.setColor(defaultSelectedItemColor);
					 gg.fill(arc);
				  }
			   }

			   gg.setColor(lineColor);

			   //// 1.1.5. Retrieve the menu element and subparts.
			   ////        This part is hackish, and will be until PieMenu
			   ////        implements the full JMenu interface.
			   item = (JComponent) list.get(i);
			   //text = getItemText(item, i);
			   //icon = getItemIcon(item, i);

			   //// 1.1.6. Draw a chevron to represent submenus.
			   /*if (item instanceof PieMenu) {
				  renderSubmenuIcon(gg, radius, radius, getSubmenuIcon(),
								currentRadian + 0.5*stepRadian, radius);
			   }*/

			   //// 1.1.7. Render the text and icon. If the clipping flag is
			   ////        on, temporarily clip the output so it won't go
			   ////        out of bounds.
			   if (getAllClipping() == true) {
				  oldClip = gg.getClip();
				  gg.setClip(arc);
			   }
			   /*if (icon == null) {
				  renderString(gg, radius, radius, text,
						currentRadian + 0.5*stepRadian, radius, item.isEnabled());
			   }
			   else {
				  renderIcon(gg, radius, radius, icon,
						currentRadian + 0.5*stepRadian, radius, item.isEnabled());
			   }*/

			   if (getAllClipping() == true) {
				  gg.setClip(oldClip);
			   }

			   //// 1.1.8. Draw the arc lines. Don't draw one if there is
			   ////        only one item.
			   gg.setColor(getLineColor());
			   if (numItems > 1) {
				  gg.draw(arc);
			   }

			   //// 1.1.9. Prepare for the next iteration / pie slice.
			   currentRadian += stepRadian;
			} // of for
		 } // of if numItems > 0


		 //// 2.1. Fill the small circle in the center.
		 gg.setColor(getFillColor());
		 gg.fill(smallCircle);
		 if (selectedItem < 0) {
			gg.setColor(getSelectedColor());
			gg.fill(smallCircle);
		 }

		 //// 2.2. Draw the line around the small circle in the center.
		 gg.setColor(getLineColor());
		 gg.draw(smallCircle);

		 //// 3. Draw the line around the outer boundary of the PieMenu.
		 gg.setColor(getLineColor());
		 gg.drawOval(0, 0, 2*radius, 2*radius);

		 //// 4. Restore whatever settings we modified.
		 gg.setRenderingHints(oldHints);
		 gg.setColor(oldc);
	  } // of method
	  
	  public static void main(String[] args){
	  	SunburstMenuBasic menu = new SunburstMenuBasic();
	  	
	  	menu.addItem(new JLabel("hello"));
	  	menu.addItem(new JLabel("world"));
	  	menu.addItem(new JLabel("this"));
	  	menu.addItem(new JLabel("play"));
	  	menu.addItem(new JLabel("let"));
	  	menu.addItem(new JLabel("news"));
	  	
	  	JFrame frame = new JFrame("Sunburst");
	  	frame.getContentPane().add(menu);
	  	frame.setSize(new Dimension(400,400));
	  	frame.show();
	  }

}
